package com.micro.modual.service.impl;

import com.micro.common.MicroResponseCode;
import com.micro.core.exception.BizException;
import com.micro.core.frame.service.impl.AbstractBasicsServiceImpl;
import com.micro.core.resp.RespJson;
import com.micro.modual.entity.Region;
import com.micro.modual.extension.RegionExtension;
import com.micro.modual.mapper.RegionMapper;
import com.micro.modual.model.bo.region.RegionBO;
import com.micro.modual.service.RegionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
*  <h1>行政区划  实现</h1>
 * @author LevelCoder
 * @version V1.0.0
 * @email LevelCoder@126.com
 * @date 2020-08-04 00:11:10
 */
@Service("regionService")
public class RegionServiceImpl extends AbstractBasicsServiceImpl<Region,Long> implements RegionService {

    @Autowired
    private RegionMapper regionMapper;

    /**
     * <h2>新增行政区划详情</h2>
     * @param regionBO {@link RegionBO} 行政区划 新增/修改 请求对象
     * @return {@link RespJson} 返回结果基础类
     */
    @Override
    public RespJson addRegion(RegionBO regionBO) {
        Region region = RegionExtension.converAddRegion(regionBO);
        regionMapper.insertSelective(region);
        return new RespJson(MicroResponseCode.SUCCESS.getResponseCode(), MicroResponseCode.SUCCESS.getResponseMessage());
    }

    /**
     * <h2>修改行政区划详情</h2>
     * @param regionBO  {@link RegionBO} 行政区划 新增/修改 请求对象
     * @return {@link RespJson} 返回结果基础类
     */
    @Override
    public RespJson editRegion(RegionBO regionBO) {
        Region region = RegionExtension.converEditRegion(regionBO);
        regionMapper.updateByPrimaryKeySelective(region);
        return new RespJson(MicroResponseCode.SUCCESS.getResponseCode(),MicroResponseCode.SUCCESS.getResponseMessage());

    }

    /**
     * <h2>根据主键编号删除行政区划信息</h2>
     * @param id  行政区划 主键编号
     * @return  {@link RespJson} 返回结果基础类
     */

    @Override
    public RespJson deleteRegion(Long id) {
        regionMapper.deleteByPrimaryKey(id);
        return new RespJson(MicroResponseCode.SUCCESS.getResponseCode(),MicroResponseCode.SUCCESS.getResponseMessage());
    }

}
